package com.leospa.properties;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class ConfigPropertiesFile {


	public static String SERVER_ADDRESS;
	public static int PORT;
	public static int TIMEOUT_MS;
	public static int TIMEOUT_OPTION_SCREEN;
	public static int TIMEOUT_ERROR_SCREEN;
	public static String CARD_TYPE;
	public static String LFComPort;
	public static String LFSerielNumCmd;
	public static String HFComPort;
	public static String HFSerielNumCmd;
	public static String RelayComPort;
	public static String RelaySwitch1_on;
	public static String RelaySwitch1_off;
	public static String RelaySwitch2_on;
	public static String RelaySwitch2_off;
	public static String RelaySwitch3_on;
	public static String RelaySwitch3_off;
	public static String RelaySwitch4_on;
	public static String RelaySwitch4_off;
	
	public static String RelaySwitch1_on_linux;
	public static String RelaySwitch1_off_linux;
	public static String RelaySwitch2_on_linux;
	public static String RelaySwitch2_off_linux;
	public static String RelaySwitch3_on_linux;
	public static String RelaySwitch3_off_linux;
	public static String RelaySwitch4_on_linux;
	public static String RelaySwitch4_off_linux;
	public static String Relay1_status_window;
	public static String Relay1_status_linux;
	
	public static int CARD_READ_DELAY;;
	public static int THANKS_SCREEN_TIMEOUT_MS;
	public static int TIME_FORMAT;
	public static String DATE_FORMAT;
	public static boolean DEMO_MODE= false;
	public static boolean FULLSCREEN_MODE = false;
	public static String OS_TYPE ;
	
	public static boolean DEBUG_MODE_ON;
	public static boolean ALWAYS_ON_TOP;
	
	static {
		Properties prop = new Properties();
		FileInputStream input = null;
		try {

			input = new FileInputStream("./config.properties");
			BufferedReader in = new BufferedReader(new InputStreamReader(input, "UTF8"));
			prop.load(in);
			OS_TYPE = prop.getProperty("OS_TYPE");
			SERVER_ADDRESS = prop.getProperty("SERVER_ADDRESS");
			PORT = Integer.parseInt(prop.getProperty("PORT"));
			TIMEOUT_MS = Integer.parseInt(prop.getProperty("TIMEOUT_MS"));	
			TIMEOUT_OPTION_SCREEN = Integer.parseInt(prop.getProperty("TIMEOUT_OPTION_SCREEN"));
			TIMEOUT_ERROR_SCREEN = Integer.parseInt(prop.getProperty("TIMEOUT_ERROR_SCREEN"));
			CARD_READ_DELAY = Integer.parseInt(prop.getProperty("CARD_READ_DELAY"));
			TIME_FORMAT = Integer.parseInt(prop.getProperty("TIME_FORMAT"));
			DATE_FORMAT = prop.getProperty("DATE_FORMAT");
			
			CARD_TYPE =  prop.getProperty("CARD_TYPE");
			LFComPort =  prop.getProperty("LFComPort");
			LFSerielNumCmd =  prop.getProperty("LFSerielNumCmd");
			HFComPort =  prop.getProperty("HFComPort");
			HFSerielNumCmd =  prop.getProperty("HFSerielNumCmd");
			RelayComPort =  prop.getProperty("RelayComPort");
			
			RelaySwitch1_on =  prop.getProperty("RelaySwitch1_on");
			RelaySwitch1_off =  prop.getProperty("RelaySwitch1_off");
			RelaySwitch2_on =  prop.getProperty("RelaySwitch2_on");
			RelaySwitch2_off =  prop.getProperty("RelaySwitch2_off");			
			RelaySwitch3_on =  prop.getProperty("RelaySwitch3_on");
			RelaySwitch3_off =  prop.getProperty("RelaySwitch3_off");
			RelaySwitch4_on =  prop.getProperty("RelaySwitch4_on");
			RelaySwitch4_off =  prop.getProperty("RelaySwitch4_off");
			
			RelaySwitch1_on_linux =  prop.getProperty("RelaySwitch1_on_linux");
			RelaySwitch1_off_linux =  prop.getProperty("RelaySwitch1_off_linux");
			RelaySwitch2_on_linux =  prop.getProperty("RelaySwitch2_on_linux");
			RelaySwitch2_off_linux =  prop.getProperty("RelaySwitch2_off_linux");			
			RelaySwitch3_on_linux =  prop.getProperty("RelaySwitch3_on_linux");
			RelaySwitch3_off_linux =  prop.getProperty("RelaySwitch3_off_linux");
			RelaySwitch4_on_linux =  prop.getProperty("RelaySwitch4_on_linux");
			RelaySwitch4_off_linux =  prop.getProperty("RelaySwitch4_off_linux");
			Relay1_status_window =  prop.getProperty("Relay1_status_window");
			Relay1_status_linux =  prop.getProperty("Relay1_status_linux");
			THANKS_SCREEN_TIMEOUT_MS = Integer.parseInt(prop.getProperty("THANKS_SCREEN_TIMEOUT_MS"));
			String demo = prop.getProperty("DEMO_MODE");
			if(demo.equals("true")){
				DEMO_MODE = true;
			}
			
			String fullscreen = prop.getProperty("FULLSCREEN_MODE");
			if(fullscreen.equals("true")){
				FULLSCREEN_MODE = true;
			}
			
			String debugOn = prop.getProperty("DEBUG_MODE_ON");
			String alwaysOnTop = prop.getProperty("ALWAYS_ON_TOP");
			
			if(debugOn.equalsIgnoreCase("true")){
				DEBUG_MODE_ON = true;
			}else{
				DEBUG_MODE_ON = false;
			}
			
			if(alwaysOnTop.equalsIgnoreCase("true")){
				ALWAYS_ON_TOP = true;
			}else{
				ALWAYS_ON_TOP = false;
			}
			
			
		} catch (Exception e) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){e.printStackTrace();}
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException e) {
					if(ConfigPropertiesFile.DEBUG_MODE_ON == true){e.printStackTrace();}
				}
			}
		}
	}



}
